<template>
    <div>
        <a-button @click="handClick">发送消息222</a-button>
        <a-button @click="handClose">关闭</a-button>
        <a-row>
            <a-col :span="24" v-for="(item, index) in arr" :key="index">
                <div v-html="item">
                </div>
            </a-col>
        </a-row>
    </div>
</template>
<script>
export default {
    data() {
        return {
            arr: [],
        };
    },
    mounted() {
    },
    methods: {
        sendMessage(message) {
            this.$websocket.send(message)
        },
        onClose() {
            this.arr.push('关闭了');
        },
        getMessage(e) {
            this.arr.push(e);
        },
        handClick() {
            this.sendMessage('发送数据@1234444');
        },
        handClose() {
            this.$websocket.Close();
            // console.log('this.$websocket==', this.$websocket);
        },
    },
    created() {
        //绑定
        this.$websocket.onMessage(this.getMessage);
        this.$websocket.onClose(this.onClose);
        // this.sendMessage('发送数据');

    },
    beforeDestroy() {
        // this.onbeforeunload()
    },
};
</script>
<style></style>